package com.app.bimo.library_db.dao;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.app.bimo.library_db.BookClassDataConvert;
import java.util.List;

import com.app.bimo.library_db.SearchData;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "SEARCH_DATA".
*/
public class SearchDataDao extends AbstractDao<SearchData, String> {

    public static final String TABLENAME = "SEARCH_DATA";

    /**
     * Properties of entity SearchData.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Novelid = new Property(0, String.class, "novelid", true, "NOVELID");
        public final static Property NovelName = new Property(1, String.class, "novelName", false, "NOVEL_NAME");
        public final static Property Cover = new Property(2, String.class, "cover", false, "COVER");
        public final static Property Summary = new Property(3, String.class, "summary", false, "SUMMARY");
        public final static Property Authorid = new Property(4, String.class, "authorid", false, "AUTHORID");
        public final static Property AuthorName = new Property(5, String.class, "authorName", false, "AUTHOR_NAME");
        public final static Property Uid = new Property(6, String.class, "uid", false, "UID");
        public final static Property IsTop = new Property(7, int.class, "isTop", false, "IS_TOP");
        public final static Property CategoryNames = new Property(8, String.class, "categoryNames", false, "CATEGORY_NAMES");
    }

    private final BookClassDataConvert categoryNamesConverter = new BookClassDataConvert();

    public SearchDataDao(DaoConfig config) {
        super(config);
    }
    
    public SearchDataDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"SEARCH_DATA\" (" + //
                "\"NOVELID\" TEXT PRIMARY KEY NOT NULL ," + // 0: novelid
                "\"NOVEL_NAME\" TEXT," + // 1: novelName
                "\"COVER\" TEXT," + // 2: cover
                "\"SUMMARY\" TEXT," + // 3: summary
                "\"AUTHORID\" TEXT," + // 4: authorid
                "\"AUTHOR_NAME\" TEXT," + // 5: authorName
                "\"UID\" TEXT," + // 6: uid
                "\"IS_TOP\" INTEGER NOT NULL ," + // 7: isTop
                "\"CATEGORY_NAMES\" TEXT);"); // 8: categoryNames
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"SEARCH_DATA\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, SearchData entity) {
        stmt.clearBindings();
 
        String novelid = entity.getNovelid();
        if (novelid != null) {
            stmt.bindString(1, novelid);
        }
 
        String novelName = entity.getNovelName();
        if (novelName != null) {
            stmt.bindString(2, novelName);
        }
 
        String cover = entity.getCover();
        if (cover != null) {
            stmt.bindString(3, cover);
        }
 
        String summary = entity.getSummary();
        if (summary != null) {
            stmt.bindString(4, summary);
        }
 
        String authorid = entity.getAuthorid();
        if (authorid != null) {
            stmt.bindString(5, authorid);
        }
 
        String authorName = entity.getAuthorName();
        if (authorName != null) {
            stmt.bindString(6, authorName);
        }
 
        String uid = entity.getUid();
        if (uid != null) {
            stmt.bindString(7, uid);
        }
        stmt.bindLong(8, entity.getIsTop());
 
        List categoryNames = entity.getCategoryNames();
        if (categoryNames != null) {
            stmt.bindString(9, categoryNamesConverter.convertToDatabaseValue(categoryNames));
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, SearchData entity) {
        stmt.clearBindings();
 
        String novelid = entity.getNovelid();
        if (novelid != null) {
            stmt.bindString(1, novelid);
        }
 
        String novelName = entity.getNovelName();
        if (novelName != null) {
            stmt.bindString(2, novelName);
        }
 
        String cover = entity.getCover();
        if (cover != null) {
            stmt.bindString(3, cover);
        }
 
        String summary = entity.getSummary();
        if (summary != null) {
            stmt.bindString(4, summary);
        }
 
        String authorid = entity.getAuthorid();
        if (authorid != null) {
            stmt.bindString(5, authorid);
        }
 
        String authorName = entity.getAuthorName();
        if (authorName != null) {
            stmt.bindString(6, authorName);
        }
 
        String uid = entity.getUid();
        if (uid != null) {
            stmt.bindString(7, uid);
        }
        stmt.bindLong(8, entity.getIsTop());
 
        List categoryNames = entity.getCategoryNames();
        if (categoryNames != null) {
            stmt.bindString(9, categoryNamesConverter.convertToDatabaseValue(categoryNames));
        }
    }

    @Override
    public String readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
    }    

    @Override
    public SearchData readEntity(Cursor cursor, int offset) {
        SearchData entity = new SearchData( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // novelid
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // novelName
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // cover
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // summary
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // authorid
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // authorName
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // uid
            cursor.getInt(offset + 7), // isTop
            cursor.isNull(offset + 8) ? null : categoryNamesConverter.convertToEntityProperty(cursor.getString(offset + 8)) // categoryNames
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, SearchData entity, int offset) {
        entity.setNovelid(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setNovelName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setCover(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setSummary(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setAuthorid(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setAuthorName(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setUid(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setIsTop(cursor.getInt(offset + 7));
        entity.setCategoryNames(cursor.isNull(offset + 8) ? null : categoryNamesConverter.convertToEntityProperty(cursor.getString(offset + 8)));
     }
    
    @Override
    protected final String updateKeyAfterInsert(SearchData entity, long rowId) {
        return entity.getNovelid();
    }
    
    @Override
    public String getKey(SearchData entity) {
        if(entity != null) {
            return entity.getNovelid();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(SearchData entity) {
        return entity.getNovelid() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
